 package org.example.datasource.eventhandler;

import java.util.Set;

import javax.annotation.PostConstruct;

import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent;
import org.example.datasource.Orderly;
import org.springframework.stereotype.Component;

import com.alibaba.otter.canal.connector.core.consumer.CommonMessage;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Component
public class UpdateHandler  extends AbstractEventHandler implements Orderly{

    private final String name = "UPDATE";
    @PostConstruct
    public void init() {
        register(name, this);
        subscribe(name);
    }
    
    @Override
    public void hand(CommonMessage msg) {
        log.info("dbase =>{},table=>{}",msg.getDatabase(),msg.getTable());
        int size = msg.getOld().size();
        log.info("updated records =>{}",size);
        for(int i=0;i<size;i++) {
            Set<String> cols = msg.getOld().get(i).keySet();
            if(cols.contains("user_name")) {
                log.info("update user_name=>{}",msg.getData().get(i).get("user_name"));
            }
        }
    }

    @Override
    public void updatedNode(PathChildrenCacheEvent event) {
        // TODO Auto-generated method stub
         
    }

    @Override
    public void deletedNode(PathChildrenCacheEvent event) {
        // TODO Auto-generated method stub
         
    }

    @Override
    public void addedNode(PathChildrenCacheEvent event) {
        // TODO Auto-generated method stub
         
    }


}
